package com.itheima.tliasmanagent.controller;

import com.itheima.tliasmanagent.anno.Log;
import com.itheima.tliasmanagent.pojo.Emp;
import com.itheima.tliasmanagent.pojo.EmpQueryParam;
import com.itheima.tliasmanagent.pojo.PageBean;
import com.itheima.tliasmanagent.pojo.Result;
import com.itheima.tliasmanagent.service.EmpService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import java.time.LocalDate;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/emps")
@Slf4j
public class EmpController {

    @Autowired
    private EmpService empService;



  /*  @GetMapping
    public Result page(@RequestParam(defaultValue = "1") Integer page,
                       @RequestParam(defaultValue = "10") Integer pageSize){
        log.info("page:"+page);
        log.info("pageSize:"+pageSize);
       PageBean pagebean= empService.page(page,pageSize);// 完成分页查询

        return Result.success(pagebean);
    }*/
  @GetMapping
  public Result page(EmpQueryParam empQueryParam){
      log.info("data:"+empQueryParam);
      PageBean pagebean= empService.page(empQueryParam);

    //  PageBean pagebean= empService.page(page,pageSize);// 完成分页查询
      return Result.success(pagebean);
  }


  @PostMapping
  @Log
  public Result save(@RequestBody Emp emp) throws Exception {
      log.info(emp.toString());
      empService.save(emp);
      return Result.success();
  }

/*  @DeleteMapping
  public Result delete(Integer[] ids){
      log.info("批量删除员工信息 {}", Arrays.toString(ids));
      return Result.success();
  }*/

    @DeleteMapping
    @Log
    public Result delete(@RequestParam List<Integer> ids){
        log.info("批量删除员工信息 {}", ids);
        empService.deleteByIds(ids);
        return Result.success();
    }

    @GetMapping("/{id}")
    public Result getInfo(@PathVariable Integer id){
       Emp emp= empService.getInfo(id);
        return Result.success(emp);
    }

    @PutMapping
    @Log
    public Result update(@RequestBody Emp emp){



            empService.update(emp);
            return Result.success();

    }
}
